<html>
<head><meta charset="utf-8"><title>Using two statics to &quot;mark a region&quot; · t-lang/wg-unsafe-code-guidelines · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/index.html">t-lang/wg-unsafe-code-guidelines</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using.20two.20statics.20to.20.22mark.20a.20region.22.html">Using two statics to &quot;mark a region&quot;</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="172203802"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using%20two%20statics%20to%20%22mark%20a%20region%22/near/172203802" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using.20two.20statics.20to.20.22mark.20a.20region.22.html#172203802">(Aug 01 2019 at 09:05)</a>:</h4>
<p>I think I saw someone once propose to use two statics to mark a region of memory, i.e. the linker would later be instructed to set one static to the beginning and one to the end.<br>
Seems like this caused miscompilations before: <a href="https://stefansf.de/post/pointers-are-more-abstract-than-you-might-expect/" target="_blank" title="https://stefansf.de/post/pointers-are-more-abstract-than-you-might-expect/">https://stefansf.de/post/pointers-are-more-abstract-than-you-might-expect/</a> (GCC changed behavior in that case but I dont know what LLVM does)</p>



<a name="172203854"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using%20two%20statics%20to%20%22mark%20a%20region%22/near/172203854" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using.20two.20statics.20to.20.22mark.20a.20region.22.html#172203854">(Aug 01 2019 at 09:06)</a>:</h4>
<p>does anyone remember where that came up? <span class="user-mention" data-user-id="119009">@eddyb</span> ?</p>



<a name="172204052"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using%20two%20statics%20to%20%22mark%20a%20region%22/near/172204052" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using.20two.20statics.20to.20.22mark.20a.20region.22.html#172204052">(Aug 01 2019 at 09:09)</a>:</h4>
<p>(also WTF, that post was published the <em>exact same day</em> as my own <a href="https://www.ralfj.de/blog/2018/07/24/pointers-and-bytes.html" target="_blank" title="https://www.ralfj.de/blog/2018/07/24/pointers-and-bytes.html">https://www.ralfj.de/blog/2018/07/24/pointers-and-bytes.html</a>...)</p>



<a name="172204074"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using%20two%20statics%20to%20%22mark%20a%20region%22/near/172204074" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using.20two.20statics.20to.20.22mark.20a.20region.22.html#172204074">(Aug 01 2019 at 09:09)</a>:</h4>
<p>I've used <code>asm!</code> to mark regions of code before, and that did not cause micompilations</p>



<a name="172204180"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using%20two%20statics%20to%20%22mark%20a%20region%22/near/172204180" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using.20two.20statics.20to.20.22mark.20a.20region.22.html#172204180">(Aug 01 2019 at 09:10)</a>:</h4>
<p>Either way, is that a use case that the language supports?</p>



<a name="172204230"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using%20two%20statics%20to%20%22mark%20a%20region%22/near/172204230" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using.20two.20statics.20to.20.22mark.20a.20region.22.html#172204230">(Aug 01 2019 at 09:11)</a>:</h4>
<p>Also, why does the example use two statics, instead of a static array and a size_t in C?</p>



<a name="172204273"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using%20two%20statics%20to%20%22mark%20a%20region%22/near/172204273" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using.20two.20statics.20to.20.22mark.20a.20region.22.html#172204273">(Aug 01 2019 at 09:12)</a>:</h4>
<p>That would have avoided the problem</p>



<a name="172204284"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using%20two%20statics%20to%20%22mark%20a%20region%22/near/172204284" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using.20two.20statics.20to.20.22mark.20a.20region.22.html#172204284">(Aug 01 2019 at 09:12)</a>:</h4>
<p>(to obtain the end pointer, you need to offset the start pointer with the size_t, and that returns a pointer with the right provenance)</p>



<a name="172204754"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using%20two%20statics%20to%20%22mark%20a%20region%22/near/172204754" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using.20two.20statics.20to.20.22mark.20a.20region.22.html#172204754">(Aug 01 2019 at 09:20)</a>:</h4>
<p>no idea why this was done the way it was</p>



<a name="172204770"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using%20two%20statics%20to%20%22mark%20a%20region%22/near/172204770" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using.20two.20statics.20to.20.22mark.20a.20region.22.html#172204770">(Aug 01 2019 at 09:20)</a>:</h4>
<p>but it's the same thing I saw someone ask/propose for use in Rust</p>



<a name="172204783"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using%20two%20statics%20to%20%22mark%20a%20region%22/near/172204783" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using.20two.20statics.20to.20.22mark.20a.20region.22.html#172204783">(Aug 01 2019 at 09:20)</a>:</h4>
<p>It seems that it was always done that way in the Linux kernel</p>



<a name="172204794"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using%20two%20statics%20to%20%22mark%20a%20region%22/near/172204794" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using.20two.20statics.20to.20.22mark.20a.20region.22.html#172204794">(Aug 01 2019 at 09:20)</a>:</h4>
<p>and it was always broken, but people started seeing issues as the GCC version was updated</p>



<a name="172204805"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using%20two%20statics%20to%20%22mark%20a%20region%22/near/172204805" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using.20two.20statics.20to.20.22mark.20a.20region.22.html#172204805">(Aug 01 2019 at 09:20)</a>:</h4>
<p>they had linker scripts to do that</p>



<a name="172204832"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using%20two%20statics%20to%20%22mark%20a%20region%22/near/172204832" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using.20two.20statics.20to.20.22mark.20a.20region.22.html#172204832">(Aug 01 2019 at 09:21)</a>:</h4>
<p>the linux kernel mailing list never considered changing the linker scripts, so I don't know whether that would have been possible</p>



<a name="172204836"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using%20two%20statics%20to%20%22mark%20a%20region%22/near/172204836" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using.20two.20statics.20to.20.22mark.20a.20region.22.html#172204836">(Aug 01 2019 at 09:21)</a>:</h4>
<p>I don't see why it wouldn't</p>



<a name="172204921"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using%20two%20statics%20to%20%22mark%20a%20region%22/near/172204921" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using.20two.20statics.20to.20.22mark.20a.20region.22.html#172204921">(Aug 01 2019 at 09:22)</a>:</h4>
<p>they ended up using <code>black_box</code> instead to make the arrays opaque to the optimizer</p>



<a name="172204933"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using%20two%20statics%20to%20%22mark%20a%20region%22/near/172204933" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using.20two.20statics.20to.20.22mark.20a.20region.22.html#172204933">(Aug 01 2019 at 09:23)</a>:</h4>
<p>its duct-tape all the way down</p>



<a name="172205072"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using%20two%20statics%20to%20%22mark%20a%20region%22/near/172205072" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using.20two.20statics.20to.20.22mark.20a.20region.22.html#172205072">(Aug 01 2019 at 09:25)</a>:</h4>
<blockquote>
<p>its duct-tape all the way down</p>
</blockquote>
<p>indeed :/</p>



<a name="172732143"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using%20two%20statics%20to%20%22mark%20a%20region%22/near/172732143" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using.20two.20statics.20to.20.22mark.20a.20region.22.html#172732143">(Aug 08 2019 at 02:11)</a>:</h4>
<p>I've needed to mark the end of the statics in my binary before</p>



<a name="172732204"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using%20two%20statics%20to%20%22mark%20a%20region%22/near/172732204" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using.20two.20statics.20to.20.22mark.20a.20region.22.html#172732204">(Aug 08 2019 at 02:12)</a>:</h4>
<p>well, in my ROM, it was for GBA, so execution and the whole address space are very well defined with no OS meddling in your way</p>



<a name="172746764"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using%20two%20statics%20to%20%22mark%20a%20region%22/near/172746764" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using.20two.20statics.20to.20.22mark.20a.20region.22.html#172746764">(Aug 08 2019 at 08:14)</a>:</h4>
<p>right but the compiler is still meddling ;)</p>



<a name="172746768"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using%20two%20statics%20to%20%22mark%20a%20region%22/near/172746768" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using.20two.20statics.20to.20.22mark.20a.20region.22.html#172746768">(Aug 08 2019 at 08:14)</a>:</h4>
<p><span class="user-mention" data-user-id="224471">@Lokathor</span> so why didn't it work to mark begin + length instead?</p>



<a name="172747309"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using%20two%20statics%20to%20%22mark%20a%20region%22/near/172747309" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using.20two.20statics.20to.20.22mark.20a.20region.22.html#172747309">(Aug 08 2019 at 08:24)</a>:</h4>
<p>So <a href="https://github.com/rust-console/gba/blob/master/linker.ld#L22" target="_blank" title="https://github.com/rust-console/gba/blob/master/linker.ld#L22">the linker</a> does a start and end thing for the <code>.data</code>, and for <code>.bss</code> it just marks the end. Then <a href="https://github.com/rust-console/gba/blob/master/crt0.s#L62" target="_blank" title="https://github.com/rust-console/gba/blob/master/crt0.s#L62">crt0</a> copies necessary data at boot before entering <code>main</code>, and then <a href="https://github.com/rust-console/gba/blob/master/src/lib.rs#L48" target="_blank" title="https://github.com/rust-console/gba/blob/master/src/lib.rs#L48">inside rust</a> we just declare an extern static with the right name and let the linker figure it out.</p>
<p>And, well, it seems to work out.</p>



<a name="172747561"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using%20two%20statics%20to%20%22mark%20a%20region%22/near/172747561" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using.20two.20statics.20to.20.22mark.20a.20region.22.html#172747561">(Aug 08 2019 at 08:29)</a>:</h4>
<p>it works out until LLVM sees you are doing cross-object arithmetic...</p>



<a name="172747587"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using%20two%20statics%20to%20%22mark%20a%20region%22/near/172747587" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using.20two.20statics.20to.20.22mark.20a.20region.22.html#172747587">(Aug 08 2019 at 08:30)</a>:</h4>
<p>LLVM considers each static its own "allocated object"</p>



<a name="172747621"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using%20two%20statics%20to%20%22mark%20a%20region%22/near/172747621" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using.20two.20statics.20to.20.22mark.20a.20region.22.html#172747621">(Aug 08 2019 at 08:30)</a>:</h4>
<p>not sure what the best solution here is. maybe as a start we should have an issue tracking this somewhere.</p>



<a name="172749736"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using%20two%20statics%20to%20%22mark%20a%20region%22/near/172749736" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using.20two.20statics.20to.20.22mark.20a.20region.22.html#172749736">(Aug 08 2019 at 09:08)</a>:</h4>
<p><span class="user-mention" data-user-id="224471">@Lokathor</span> is there a way for the linker to write the length of the region to a static ?</p>



<a name="172750114"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using%20two%20statics%20to%20%22mark%20a%20region%22/near/172750114" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using.20two.20statics.20to.20.22mark.20a.20region.22.html#172750114">(Aug 08 2019 at 09:16)</a>:</h4>
<p>I don't know about the linker used for that target but some linkers definitely support that</p>



<a name="172750342"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using%20two%20statics%20to%20%22mark%20a%20region%22/near/172750342" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using.20two.20statics.20to.20.22mark.20a.20region.22.html#172750342">(Aug 08 2019 at 09:21)</a>:</h4>
<p>I did not write that linker script, so i don't know</p>



<a name="172750402"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using%20two%20statics%20to%20%22mark%20a%20region%22/near/172750402" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using.20two.20statics.20to.20.22mark.20a.20region.22.html#172750402">(Aug 08 2019 at 09:22)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> it's just so that you can know the base address for where your own allocator should start. it's not intended for cross-object pointer jumping or anything like that</p>



<a name="172750421"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using%20two%20statics%20to%20%22mark%20a%20region%22/near/172750421" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using.20two.20statics.20to.20.22mark.20a.20region.22.html#172750421">(Aug 08 2019 at 09:23)</a>:</h4>
<p>Is this GNU ld? Then see the example for <code>SIZEOF</code> near the end of this page <a href="https://sourceware.org/binutils/docs/ld/Builtin-Functions.html#Builtin-Functions" target="_blank" title="https://sourceware.org/binutils/docs/ld/Builtin-Functions.html#Builtin-Functions">https://sourceware.org/binutils/docs/ld/Builtin-Functions.html#Builtin-Functions</a></p>



<a name="172750426"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using%20two%20statics%20to%20%22mark%20a%20region%22/near/172750426" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using.20two.20statics.20to.20.22mark.20a.20region.22.html#172750426">(Aug 08 2019 at 09:23)</a>:</h4>
<p>uhm</p>



<a name="172750430"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using%20two%20statics%20to%20%22mark%20a%20region%22/near/172750430" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using.20two.20statics.20to.20.22mark.20a.20region.22.html#172750430">(Aug 08 2019 at 09:23)</a>:</h4>
<p>yeah, gnu binutils for arm</p>



<a name="172751622"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using%20two%20statics%20to%20%22mark%20a%20region%22/near/172751622" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using.20two.20statics.20to.20.22mark.20a.20region.22.html#172751622">(Aug 08 2019 at 09:48)</a>:</h4>
<blockquote>
<p><span class="user-mention silent" data-user-id="120791">RalfJ</span> it's just so that you can know the base address for where your own allocator should start. it's not intended for cross-object pointer jumping or anything like that</p>
</blockquote>
<p>the thing is, <code>BEGIN</code> and <code>END</code> are different objects for LLVM</p>



<a name="172751631"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using%20two%20statics%20to%20%22mark%20a%20region%22/near/172751631" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using.20two.20statics.20to.20.22mark.20a.20region.22.html#172751631">(Aug 08 2019 at 09:48)</a>:</h4>
<p>so if you subtract them as pointers (<code>offset_from</code>), you won't get well-defined results</p>



<a name="172751635"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using%20two%20statics%20to%20%22mark%20a%20region%22/near/172751635" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using.20two.20statics.20to.20.22mark.20a.20region.22.html#172751635">(Aug 08 2019 at 09:48)</a>:</h4>
<p>if you compare <code>BEGIN.add(n)</code> with <code>END</code> as pointers, that can be optimized to <code>false</code> without even looking at <code>n</code></p>



<a name="172751646"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using%20two%20statics%20to%20%22mark%20a%20region%22/near/172751646" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using.20two.20statics.20to.20.22mark.20a.20region.22.html#172751646">(Aug 08 2019 at 09:49)</a>:</h4>
<p>you can try comparing as integers instead, that <em>should</em> be well-defined but LLVM has bugs</p>



<a name="172751707"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using%20two%20statics%20to%20%22mark%20a%20region%22/near/172751707" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using.20two.20statics.20to.20.22mark.20a.20region.22.html#172751707">(Aug 08 2019 at 09:50)</a>:</h4>
<p>I think if you use <code>END.wrapping_offset_from(BEGIN)</code>, and then never use <code>END</code> again, that should work</p>



<a name="172756742"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using%20two%20statics%20to%20%22mark%20a%20region%22/near/172756742" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using.20two.20statics.20to.20.22mark.20a.20region.22.html#172756742">(Aug 08 2019 at 11:32)</a>:</h4>
<p>writing a linker script that does array+size feels simpler than writing one that generates two arrays appropriately</p>



<a name="172756761"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using%20two%20statics%20to%20%22mark%20a%20region%22/near/172756761" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using.20two.20statics.20to.20.22mark.20a.20region.22.html#172756761">(Aug 08 2019 at 11:32)</a>:</h4>
<p>doing the simplest thing avoids UB, so why do the complicated thing  that's often UB ?</p>



<a name="172792433"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using%20two%20statics%20to%20%22mark%20a%20region%22/near/172792433" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using.20two.20statics.20to.20.22mark.20a.20region.22.html#172792433">(Aug 08 2019 at 18:45)</a>:</h4>
<p>A perfect reason to use 2 symbols to mark beginning and the end is that it saves space.</p>



<a name="172792442"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using%20two%20statics%20to%20%22mark%20a%20region%22/near/172792442" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using.20two.20statics.20to.20.22mark.20a.20region.22.html#172792442">(Aug 08 2019 at 18:45)</a>:</h4>
<p>symbols, being a link-time concept, take 0 bytes in the loaded binary.</p>



<a name="172792703"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using%20two%20statics%20to%20%22mark%20a%20region%22/near/172792703" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using.20two.20statics.20to.20.22mark.20a.20region.22.html#172792703">(Aug 08 2019 at 18:48)</a>:</h4>
<p>(and obviously these symbols should end up in your code as <code>*const u8</code> pointers, not statics of T)</p>



<a name="172831403"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using%20two%20statics%20to%20%22mark%20a%20region%22/near/172831403" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using.20two.20statics.20to.20.22mark.20a.20region.22.html#172831403">(Aug 09 2019 at 07:28)</a>:</h4>
<blockquote>
<p>(and obviously these symbols should end up in your code as <code>*const u8</code> pointers, not statics of T)</p>
</blockquote>
<p>how would one do that? seems like a static is the usual way to get an address from the linker to the program</p>



<a name="172834964"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using%20two%20statics%20to%20%22mark%20a%20region%22/near/172834964" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using.20two.20statics.20to.20.22mark.20a.20region.22.html#172834964">(Aug 09 2019 at 08:47)</a>:</h4>
<p><span class="user-mention" data-user-id="123586">@nagisa</span> when one uses two symbols, the linker has to somehow insert two addresses there</p>



<a name="172834976"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using%20two%20statics%20to%20%22mark%20a%20region%22/near/172834976" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using.20two.20statics.20to.20.22mark.20a.20region.22.html#172834976">(Aug 09 2019 at 08:47)</a>:</h4>
<p>why can't the linker insert the address in one symbol, and (end - begin) in the other ?</p>



<a name="172864915"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using%20two%20statics%20to%20%22mark%20a%20region%22/near/172864915" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using.20two.20statics.20to.20.22mark.20a.20region.22.html#172864915">(Aug 09 2019 at 16:20)</a>:</h4>
<p>You don’t need to store the addresses, referring to a symbol will cause linker to replace it with an address of this symbol in-place.</p>



<a name="172864953"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using%20two%20statics%20to%20%22mark%20a%20region%22/near/172864953" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using.20two.20statics.20to.20.22mark.20a.20region.22.html#172864953">(Aug 09 2019 at 16:21)</a>:</h4>
<p>the same way <code>call foo</code> instruction does not store the address of <code>foo</code> "somewhere" first, but rather calls the address of foo directly.</p>



<a name="172865049"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using%20two%20statics%20to%20%22mark%20a%20region%22/near/172865049" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using.20two.20statics.20to.20.22mark.20a.20region.22.html#172865049">(Aug 09 2019 at 16:22)</a>:</h4>
<blockquote>
<blockquote>
<p>(and obviously these symbols should end up in your code as <code>*const u8</code> pointers, not statics of T)</p>
</blockquote>
<p>how would one do that? seems like a static is the usual way to get an address from the linker to the program</p>
</blockquote>
<p>A good question. <code>&amp;symbol as *const u8</code>?</p>



<a name="172865101"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using%20two%20statics%20to%20%22mark%20a%20region%22/near/172865101" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using.20two.20statics.20to.20.22mark.20a.20region.22.html#172865101">(Aug 09 2019 at 16:23)</a>:</h4>
<p>I guess that’s the thing where it is not clear whether <code>symbol</code> is an object of <code>u8</code> or an object of unknown dimensions.</p>



<a name="172873914"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using%20two%20statics%20to%20%22mark%20a%20region%22/near/172873914" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using.20two.20statics.20to.20.22mark.20a.20region.22.html#172873914">(Aug 09 2019 at 18:00)</a>:</h4>
<p>it better be a ZST if there's not definitely some memory there</p>



<a name="172874200"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using%20two%20statics%20to%20%22mark%20a%20region%22/near/172874200" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using.20two.20statics.20to.20.22mark.20a.20region.22.html#172874200">(Aug 09 2019 at 18:04)</a>:</h4>
<p>I don't know why it would matter? The best plan either way is to cast the address of the marker to usize and avoid all of LLVM's crazytown by doing all of your address operations on usize values.</p>



<a name="172874240"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using%20two%20statics%20to%20%22mark%20a%20region%22/near/172874240" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using.20two.20statics.20to.20.22mark.20a.20region.22.html#172874240">(Aug 09 2019 at 18:04)</a>:</h4>
<p><code>static FOO: u8</code> promises the compiler there is a byte of memory there</p>



<a name="172874295"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using%20two%20statics%20to%20%22mark%20a%20region%22/near/172874295" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using.20two.20statics.20to.20.22mark.20a.20region.22.html#172874295">(Aug 09 2019 at 18:05)</a>:</h4>
<p>oh i see, sorry, i misread. Yes, you also want a valid byte at wherever it gets puts</p>



<a name="172969930"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using%20two%20statics%20to%20%22mark%20a%20region%22/near/172969930" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using.20two.20statics.20to.20.22mark.20a.20region.22.html#172969930">(Aug 11 2019 at 13:54)</a>:</h4>
<p>Can't one write <code>static FOO: *const u8</code>; ?</p>



<a name="172970196"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using%20two%20statics%20to%20%22mark%20a%20region%22/near/172970196" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using.20two.20statics.20to.20.22mark.20a.20region.22.html#172970196">(Aug 11 2019 at 14:02)</a>:</h4>
<p>That still implies the symbol refers to valid memory, only now it has to be pointer sized instead of just one byte</p>



<a name="173015146"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using%20two%20statics%20to%20%22mark%20a%20region%22/near/173015146" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using.20two.20statics.20to.20.22mark.20a.20region.22.html#173015146">(Aug 12 2019 at 11:19)</a>:</h4>
<p>Ah, gotcha.  Wouldn't one byte also be sub-optimal?</p>



<a name="173015217"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using%20two%20statics%20to%20%22mark%20a%20region%22/near/173015217" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using.20two.20statics.20to.20.22mark.20a.20region.22.html#173015217">(Aug 12 2019 at 11:20)</a>:</h4>
<p>e.g. what we want is <code>static FOO: Zst;</code> and for <code>&amp;Foo</code> to have an address chosen by the linker</p>



<a name="173015229"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using%20two%20statics%20to%20%22mark%20a%20region%22/near/173015229" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using.20two.20statics.20to.20.22mark.20a.20region.22.html#173015229">(Aug 12 2019 at 11:20)</a>:</h4>
<p>such that if then the other "end" pointer, or the size are zero, no memory needs to be allocated for this</p>



<a name="173015247"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using%20two%20statics%20to%20%22mark%20a%20region%22/near/173015247" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using.20two.20statics.20to.20.22mark.20a.20region.22.html#173015247">(Aug 12 2019 at 11:21)</a>:</h4>
<p>otherwise when the size is zero, <code>static FOO: u8;</code> would need to be dereferenceable for one byte, but this wouldn't be the case</p>



<a name="173015341"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using%20two%20statics%20to%20%22mark%20a%20region%22/near/173015341" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using.20two.20statics.20to.20.22mark.20a.20region.22.html#173015341">(Aug 12 2019 at 11:23)</a>:</h4>
<p>Yeah, a ZST would fine as Ralf said earlier. Although I'm not so sure we guarantee to actually give you the address of the symbol rather than e.g. <code>align_of::&lt;TheZst&gt;() as *const</code></p>



<a name="173017526"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using%20two%20statics%20to%20%22mark%20a%20region%22/near/173017526" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using.20two.20statics.20to.20.22mark.20a.20region.22.html#173017526">(Aug 12 2019 at 12:05)</a>:</h4>
<p>I recall that the implementation currently does <code>align_of::&lt;Zst&gt;() as *_</code>, but I don't think we guarantee anything beyond "the address will be suitably aligned", to avoid UB when creating a reference</p>



<a name="173058536"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using%20two%20statics%20to%20%22mark%20a%20region%22/near/173058536" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using.20two.20statics.20to.20.22mark.20a.20region.22.html#173058536">(Aug 12 2019 at 20:41)</a>:</h4>
<p>well, the symbol is placed by the linker script</p>



<a name="173058586"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using%20two%20statics%20to%20%22mark%20a%20region%22/near/173058586" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using.20two.20statics.20to.20.22mark.20a.20region.22.html#173058586">(Aug 12 2019 at 20:42)</a>:</h4>
<p>in rust you just use an extern</p>



<a name="173058623"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using%20two%20statics%20to%20%22mark%20a%20region%22/near/173058623" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Using.20two.20statics.20to.20.22mark.20a.20region.22.html#173058623">(Aug 12 2019 at 20:42)</a>:</h4>
<p>if i still follow what we're talking about</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>